package com.shujia.flink.core

import org.apache.flink.api.scala._

object Demo2batchWordCount {
  def main(args: Array[String]): Unit = {
    //创建flink batch环境

    val env: ExecutionEnvironment = ExecutionEnvironment.getExecutionEnvironment

    //1、读取数据
    //DataSet 相当于rdd
    val linesDS: DataSet[String] = env.readTextFile("data/words")

    //将单词拆分
    val countDS: AggregateDataSet[(String, Int)] = linesDS
      .flatMap(_.split(","))
      .map((_, 1))
      .groupBy(0)
      .sum(1)

    countDS.print()
  }
}
